package cn.stylefeng.guns.sys.modular.system.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.sys.modular.system.db6.entity.SysDict;
import cn.stylefeng.guns.sys.modular.system.db6.service.SysDictService;
import cn.stylefeng.guns.sys.modular.system.entity.AttendAudit;
import cn.stylefeng.guns.sys.modular.system.entity.AttendEmployeeMonth;
import cn.stylefeng.guns.sys.modular.system.entity.Enum.EmployeePositionEnum;
import cn.stylefeng.guns.sys.modular.system.model.params.AttendEmployeeMonthParam;
import cn.stylefeng.guns.sys.modular.system.model.result.AttendAuditManagerSetResult;
import cn.stylefeng.guns.sys.modular.system.service.AttendAuditService;
import cn.stylefeng.guns.sys.modular.system.service.AttendEmployeeMonthService;
import cn.stylefeng.guns.sys.modular.system.entity.AttendAuditBtyArchives;
import cn.stylefeng.guns.sys.modular.system.entity.AttendAuditBtyArea;
import cn.stylefeng.guns.sys.modular.system.entity.Enum.RoleIdEnum;
import cn.stylefeng.guns.sys.modular.system.mapper.AttendAuditBtyArchivesMapper;
import cn.stylefeng.guns.sys.modular.system.model.params.AttendAuditBtyArchivesParam;
import cn.stylefeng.guns.sys.modular.system.model.result.AttendAuditBtyArchivesCountShop;
import cn.stylefeng.guns.sys.modular.system.model.result.AttendAuditBtyArchivesResult;
import  cn.stylefeng.guns.sys.modular.system.service.AttendAuditBtyArchivesService;
import cn.stylefeng.guns.sys.modular.system.service.AttendAuditBtyAreaService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.Serializable;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author wjk
 * @since 2021-09-15
 */
@Service
public class AttendAuditBtyArchivesServiceImpl extends ServiceImpl<AttendAuditBtyArchivesMapper, AttendAuditBtyArchives> implements AttendAuditBtyArchivesService {


    @Resource
    private AttendAuditService attendAuditService;

    @Resource
    private AttendEmployeeMonthService attendEmployeeMonthService;

    @Resource
    private AttendAuditBtyAreaService attendAuditBtyAreaService;

    @Resource
    private SysDictService sysDictService;

    SimpleDateFormat sdf = new SimpleDateFormat("yyyyMM");


    @Override
    public void add(AttendAuditBtyArchivesParam param){
        AttendAuditBtyArchives entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(AttendAuditBtyArchivesParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(AttendAuditBtyArchivesParam param){
        AttendAuditBtyArchives oldEntity = getOldEntity(param);
        AttendAuditBtyArchives newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public AttendAuditBtyArchivesResult findBySpec(AttendAuditBtyArchivesParam param){
        return null;
    }

    @Override
    public List<AttendAuditBtyArchivesResult> findListBySpec(AttendAuditBtyArchivesParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(AttendAuditBtyArchivesParam param){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(AttendAuditBtyArchivesParam param){
        return null;
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private AttendAuditBtyArchives getOldEntity(AttendAuditBtyArchivesParam param) {
        return this.getById(getKey(param));
    }

    private AttendAuditBtyArchives getEntity(AttendAuditBtyArchivesParam param) {
        AttendAuditBtyArchives entity = new AttendAuditBtyArchives();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

    /**
     * 获取列表(这是为了同步相应月份的数据，获取当月的员工档案数据)
     * @param paramCondition
     * @return
     */
    @Override
    public List<AttendEmployeeMonth> getAttendEmployeeMonthBaseList(AttendEmployeeMonthParam paramCondition){
        return this.baseMapper.getAttendEmployeeMonthBaseList(paramCondition);
    }
    /**
     *  将获取到的员工数据导入到月度员工档案表中；
     * @return
     */
    @Override
    public int intoAttendEmployeeMonthList(){
        //获取到yinye数据源中的表
        AttendEmployeeMonthParam paramCondition = new AttendEmployeeMonthParam();
        List<AttendEmployeeMonth> AttendEmployeeMonthList = this.baseMapper.getAttendEmployeeMonthBaseList(paramCondition);
        String synchronousMonth = sdf.format(new Date());

        int size = 0;
        boolean flag = attendEmployeeMonthService.deleteList(synchronousMonth);
        if(flag){
            //批量增加
            size = attendEmployeeMonthService.simpleSqlInsertBatch(AttendEmployeeMonthList);
        }
        return size;
    }

    /**
     * 根据督导的手机号码，返回督导下的所有的店；
     * @author wjk
     * @Date 2021-09-15
     * @update 2021-11-05
     */
    @Override
    public List<AttendAuditBtyArea> getShopListByDdPhone(String account,String shopName) {
        //若手机号为空，则不用继续查询了，直接返回
        if (ToolUtil.isNotEmpty(account)) {
            //根据用户的手机号，获取用户的信息，获取用户的信息，包含名称；
            AttendAuditBtyArchives attendAuditBtyArchivesdd = getOneByPhone(account);
            if(ToolUtil.isEmpty(attendAuditBtyArchivesdd.getId())){
                return new ArrayList<AttendAuditBtyArea>();
            }
            //获取到用户的姓名
            String userName = attendAuditBtyArchivesdd.getXm();
            //如果是督导，督导的姓名去查询相应的店铺，获取督导的列表
            List<AttendAuditBtyArea> list = attendAuditBtyAreaService.getShowListByDdName(userName,shopName);
            //若督导列表查询不到数据则查询大店长下的店铺，返回相应的数据
            //如果是督导，督导的姓名去查询相应的店铺，获取督导的列表
            if(list.size() == 0){
                list = attendAuditBtyAreaService.getShowListByDdzName(userName,shopName);
            }
            return list;
        }
        return new ArrayList<AttendAuditBtyArea>();
    }

    /**
     * （督导设置店长页面）根据督导的手机号码，返回督导下的所有的店-分页；
     * @author wjk
     * @Date 2021-11-19
     */
    @Override
    public LayuiPageInfo getShopListByDdPhoneLayuiPage(String account, String shopName){
        //若手机号为空，则不用继续查询了，直接返回
        if (ToolUtil.isNotEmpty(account)) {
            //根据用户的手机号，获取用户的信息，获取用户的信息，包含名称；
            AttendAuditBtyArchives attendAuditBtyArchivesdd = getOneByPhone(account);
            if(ToolUtil.isEmpty(attendAuditBtyArchivesdd.getId())){
                LayuiPageInfo LayuiPageInfoNew = new LayuiPageInfo();
                LayuiPageInfoNew.setData(new ArrayList<AttendAuditBtyArea>());
                return LayuiPageInfoNew;
            }
            //获取到用户的姓名
            String userName = attendAuditBtyArchivesdd.getXm();
            //如果是督导，督导的姓名去查询相应的店铺，获取督导的列表
            List<AttendAuditBtyArea> list = attendAuditBtyAreaService.getShowListByDdName(userName,shopName);
            if(list.size() > 0){
                Page pageContext = getPageContext();
                IPage page = attendAuditBtyAreaService.getShowListByDdNameLayuiPage(pageContext,userName,shopName);
                return LayuiPageFactory.createPageInfo(page);
            }

            //若督导列表查询不到数据则查询大店长下的店铺，返回相应的数据
            if(list.size() == 0){
                list = attendAuditBtyAreaService.getShowListByDdzName(userName,shopName);
                if(list.size() > 0){
                    Page pageContext = getPageContext();
                    IPage page = attendAuditBtyAreaService.getShowListByDdzNameLayuiPage(pageContext,userName,shopName);
                    return LayuiPageFactory.createPageInfo(page);
                }
            }

        }

        LayuiPageInfo LayuiPageInfoNew = new LayuiPageInfo();
        LayuiPageInfoNew.setData(new ArrayList<AttendAuditBtyArea>());
        return LayuiPageInfoNew;
    }
    /**
     * 根据店名,手机号，获取该店的下属的所有店员信息；
     * @author wjk
     * @Date 2021-09-15
     * 增加了营运经理，督导，大店长，考勤店长，的权限判断，查询，
     * 原有查询，由督导，大店长，扩展到这个店的营运经理，和考勤的店长
     * @update 2021-11-05
     */
    @Override
    public List<AttendAuditBtyArchives> getEmployeeListByDm(String dm, String account) {
        //根据手机号，验证，这个人，是这个店的，营运经理，督导，大店长，店长，才可以获取这店的店员信息，
        Map<String,String> map = commonGetEmplistPermissions(account,dm);
        //若没有权限,则直接返回空的员工列表
        if(map.get("success").equals("false")){
            return new ArrayList<AttendAuditBtyArchives>();
        }
        //此处根据到店名查看到店内的员工列表
        LambdaQueryWrapper<AttendAuditBtyArchives> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(AttendAuditBtyArchives::getDm,dm);
        //所有员工都可以看到，不需要除去谁的信息，若需要，则添加除去，营运经理，督导等
        //除去督导的信息；queryWrapper.ne(AttendAuditBtyArchives::getZw,EmployeePositionEnum.POSITION21.getMsg());
        return this.list(queryWrapper);
    }

    /**
     * 常用的：
     * 根据店名，和操作这个店的手机号，获取这个人，是不是有查看这个店员工手机号的权限
     * @param account
     * @param dm
     * @return map: success:false ,zw:[营运经理，督导，大店长，考勤店长]
     */
    @Override
    public Map<String,String> commonGetEmplistPermissions(String account,String dm){
        Map<String,String> map = new HashMap<String, String>();
        map.put("success","false");
        if(ToolUtil.isEmpty(account)){
            return map;
        }
        if(ToolUtil.isEmpty(dm)){
            return map;
        }
        //根据用户的手机号，获取用户的信息，获取用户的信息，查询到名称
        AttendAuditBtyArchives attendAuditBtyArchivesdd = getOneByPhone(account);
        //根据手机号查询不到人员的，返回失败
        if(ToolUtil.isEmpty(attendAuditBtyArchivesdd.getId())){
            return map;
        }
        //获取到用户的姓名
        String userName = attendAuditBtyArchivesdd.getXm();

        //如果是营运经理，营运经理的姓名去查询相应的店铺，营运经理的列表
        List<AttendAuditBtyArea> listYyjl = attendAuditBtyAreaService.getShowListByYyjlName(userName,dm);
        if(listYyjl.size() > 0){
            map.put("success","true");
            map.put("zw",EmployeePositionEnum.POSITION20.getMsg());
            return map;
        }
        //如果是督导，督导的姓名去查询相应的店铺，获取督导的列表
        List<AttendAuditBtyArea> listDd = attendAuditBtyAreaService.getShowListByDdName(userName,dm);
        if(listDd.size() > 0){
            map.put("success","true");
            map.put("zw",EmployeePositionEnum.POSITION21.getMsg());
            return map;
        }
        //如果是大店长，督导的姓名去查询相应的店铺，获取督导的列表
        List<AttendAuditBtyArea> listDdz = attendAuditBtyAreaService.getShowListByDdzName(userName,dm);
        if(listDdz.size() > 0){
            map.put("success","true");
            map.put("zw",EmployeePositionEnum.POSITION22.getMsg());
            return map;
        }
        //如果是考勤店长，督导的姓名去查询相应的店铺，获取督导的列表
        List<AttendAuditBtyArea> listKqDz = attendAuditBtyAreaService.getShowListByKqDzName(userName,dm);
        if(listKqDz.size() > 0){
            map.put("success","true");
            map.put("zw",EmployeePositionEnum.POSITION23.getMsg());
            return map;
        }
        return map;
    }


    /**
     * 常用的：
     * 根据店名，和操作这个店的手机号，获取这个人，是不是有查看这个店员工手机号的权限
     * @param account
     * @param dm
     * @return map: success:false ,zw:[营运经理，督导，大店长，考勤店长]
     */
    @Override
    public Map<String,String> commonGetEmplistPermissionsOnlyddDdz(String account,String dm){
        Map<String,String> map = new HashMap<String, String>();
        map.put("success","false");
        if(ToolUtil.isEmpty(account)){
            return map;
        }
        if(ToolUtil.isEmpty(dm)){
            return map;
        }
        //根据用户的手机号，获取用户的信息，获取用户的信息，查询到名称
        AttendAuditBtyArchives attendAuditBtyArchivesdd = getOneByPhone(account);
        //根据手机号查询不到人员的，返回失败
        if(ToolUtil.isEmpty(attendAuditBtyArchivesdd.getId())){
            return map;
        }
        //获取到用户的姓名
        String userName = attendAuditBtyArchivesdd.getXm();

        //如果是督导，督导的姓名去查询相应的店铺，获取督导的列表
        List<AttendAuditBtyArea> listDd = attendAuditBtyAreaService.getShowListByDdName(userName,dm);
        if(listDd.size() > 0){
            map.put("success","true");
            map.put("zw",EmployeePositionEnum.POSITION21.getMsg());
            return map;
        }
        //如果是大店长，督导的姓名去查询相应的店铺，获取大店长的列表
        List<AttendAuditBtyArea> listDdz = attendAuditBtyAreaService.getShowListByDdzName(userName,dm);
        if(listDdz.size() > 0){
            map.put("success","true");
            map.put("zw",EmployeePositionEnum.POSITION22.getMsg());
            return map;
        }
        return map;
    }


    /**
     * 根据督导的手机号码，返回督导的手机号，职位，所拥有的店的汇总；
     * @author wjk
     * @Date 2021-09-16
     */

    @Override
    public AttendAuditBtyArchivesCountShop getShopCountShopByDdPhone(String account) {
        //返回督导的手机号，职位，所拥有的店的汇总；
        AttendAuditBtyArchivesCountShop attendAuditBtyArchivesCountShop =  new AttendAuditBtyArchivesCountShop();
        attendAuditBtyArchivesCountShop = this.baseMapper.getShopCountShopByDdPhone(account);
        //返回大店长的手机号，职位，所拥有的店的汇总；
        if(ToolUtil.isEmpty(attendAuditBtyArchivesCountShop)){
            return new AttendAuditBtyArchivesCountShop();

        }
        if(ToolUtil.isEmpty(attendAuditBtyArchivesCountShop.getSumshop())||String.valueOf(attendAuditBtyArchivesCountShop.getSumshop()).equals("0")){
            attendAuditBtyArchivesCountShop = this.baseMapper.getShopCountShopByDdzPhone(account);
        }
        return attendAuditBtyArchivesCountShop;
    }

    /**
     * 查询单条数据,根据用户的id
     *
     * @author wjk
     * @Date 2021-09-16
     */
    @Override
    public AttendAuditBtyArchives detailById(AttendAuditBtyArchivesParam attendAuditBtyArchives) {
        LambdaQueryWrapper<AttendAuditBtyArchives> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(AttendAuditBtyArchives::getId,attendAuditBtyArchives.getId());
        return this.baseMapper.selectById(attendAuditBtyArchives.getId());
    }
    /**
     * 在员工表中将员工设置为店长
     *
     * @author wjk
     * @Date 2021-09-16
     */
    @Override
    public boolean setEmployeeToDz(AttendAuditBtyArchives attendAuditBtyArchives) {
        return this.baseMapper.setEmployeeToDz(attendAuditBtyArchives);
    }

    /**
     * 根据店长的手机号码，返回店长下来自人资数据库的档案的列表；
     * @author wjk
     * @Date 2021-09-16
     */
    @Override
    public List<AttendAuditBtyArchives> getEmployeeListByDzPhone(String account) {
        AttendAuditBtyArea attendAuditBtyArea = this.attendAuditBtyAreaService.getShopInfoByDzPhone(account);
        List<AttendAuditBtyArchives> list = getEmployeeListByDm(attendAuditBtyArea.getDm(),account);
        return list;
    }

    /**
     * 此处应该判断月份 attendMonth 每月最后N天，则创建本月，其他日期创建上个月考勤
     * @param account
     * @param attendMonth
     * @return Map<String,String>  String account, String attendMonth
     */
    @Override
    public Map<String,String> intoAttendEmployeeMonthListValidationParam(String account, String attendMonth){
        Map<String,String> mapParam = new HashMap<String,String>();
        mapParam.put("account",account);
        if(ToolUtil.isNotEmpty(attendMonth) && attendMonth.length()==6){
            mapParam.put("attendMonth",attendMonth);
        }else{
            //默认创建考勤的日期是上个月
            Date date = new Date();
            attendMonth = sdf.format(this.attendEmployeeMonthService.calculateMonth(date,-1));

            Map<String,String> map = new HashMap<String,String>();

            SimpleDateFormat daySdf = new SimpleDateFormat("dd");

            SimpleDateFormat monthSdf = new SimpleDateFormat("MM");

            SimpleDateFormat yyyyMMddSdf = new SimpleDateFormat("yyyy-MM-dd");

            String day = daySdf.format(date);
            String lastMonth = monthSdf.format(this.attendEmployeeMonthService.calculateMonth(date,-1));
            String month = monthSdf.format(this.attendEmployeeMonthService.calculateMonth(date,0));

            List<SysDict> listSysDictLastDay = this.sysDictService.getSysDictAttendAuditLastDay();
            if(listSysDictLastDay.size()>0){
                SysDict sysDict= listSysDictLastDay.get(0);
                String code = sysDict.getCode();
                List<String> codeSS = attendAuditService.getLastDays(Integer.parseInt(code));
                for(int i = 0;i<codeSS.size();i++){
                    try {
                        Date codeSSday = yyyyMMddSdf.parse(codeSS.get(i));
                        if(daySdf.format(codeSSday).equals(day)){
                            //当日期属于最后几天的时候，创建本月考勤
                            //创建本月考勤
                            attendMonth = sdf.format(this.attendEmployeeMonthService.calculateMonth(date,0));

                        }
                    } catch (ParseException e) {
                        e.printStackTrace();
                    }

                }
            }
            mapParam.put("attendMonth",attendMonth);
        }

        return mapParam;
    }
    /**
     * （店长创建考勤页面）根据店长的手机号码，创建该店当月的人员的[月度]考勤信息；
     * @author wjk
     * @Date 2021-09-16
     */

    @Override
    public int intoAttendEmployeeMonthListByDzPhone(String account,String attendMonth) {
        //若电话为空，则返回吧
        if(ToolUtil.isEmpty(account)){
            return 0;
        }
        //获取考勤的月份
        Map<String,String> map = intoAttendEmployeeMonthListValidationParam(account,attendMonth);
        account = map.get("account");
        attendMonth = map.get("attendMonth");
        //根据店长手机号获取店的信息
        AttendAuditBtyArea attendAuditBtyArea = attendAuditBtyAreaService.getShopInfoByDzPhone(account);
        if(ToolUtil.isEmpty(attendAuditBtyArea.getId())){
            return 0;
        }

        //获取到yinye数据源中的表
        AttendEmployeeMonthParam paramCondition = new AttendEmployeeMonthParam();
        paramCondition.setDm(attendAuditBtyArea.getDm());
        // 判断员工状态，若工资为0 则新加员工状态，备注一下，人资过来的新员工，允许修改基本的信息，
        List<AttendEmployeeMonth> attendEmployeeMonthList = this.baseMapper.getAttendEmployeeMonthBaseList(paramCondition);

        //增加相关的id 和考勤的月份，判断是否应发工资状态为不发的，设定，考勤天数，公休天数，应发工资为零
        for(AttendEmployeeMonth attendEmployeeMonth:attendEmployeeMonthList){
            attendEmployeeMonth.setId(Long.valueOf(attendMonth+String.valueOf(attendEmployeeMonth.getBtyArchicesId())));
            attendEmployeeMonth.setAttendMonth(attendMonth);
            if(String.valueOf(attendEmployeeMonth.getPayWage()).equals("1")){
                attendEmployeeMonth.setShouldPay(BigDecimal.ZERO);
                attendEmployeeMonth.setAttendanceDays(Float.valueOf("0"));
                attendEmployeeMonth.setHolidayDays(Float.valueOf("0"));
            }
        }
        int size = 0;

        //根据店长店电话创建一条考勤审核的记录，若已经创建则返回一条记录，若创建失败则返回
        AttendAudit attendAudit = attendAuditService.addAttendAuditByDzPhone(account,attendMonth);
        if(ToolUtil.isEmpty(attendAudit)){
            return 0;
        }

        if(attendEmployeeMonthList.size()>0){

            //筛选出已经创建完成考勤的员工，然移除掉；并且增加id
            List<AttendEmployeeMonth> attendEmployeeMonthListNew = getAttendEmployeeMonthRmHaveAttendEmployee(attendEmployeeMonthList,attendMonth);

            String synchronousMonth = sdf.format(new Date());
            //添加上创建考勤月份审核信息id信息的id
            attendEmployeeMonthListNew.forEach(attendEmployeeMonth -> {
                attendEmployeeMonth.setAttendAuditId(attendAudit.getId());
            });
            //批量增加
            size = attendEmployeeMonthService.simpleSqlInsertBatch(attendEmployeeMonthListNew);
        }
        return size;
    }
    /**
     * 筛选出已经创建完成考勤的员工，然移除掉；
     * @author wjk
     * @Date 2021-09-16
     */

    private List<AttendEmployeeMonth> getAttendEmployeeMonthRmHaveAttendEmployee(List<AttendEmployeeMonth> attendEmployeeMonthList,String attendMonth) {
        //根据列表查询这些员工是否已经做过考勤记录
        List<AttendEmployeeMonth> attendEmployeeMonthListOld = attendEmployeeMonthService.getEmployeeListByAuditBtyArchiveList(attendEmployeeMonthList,attendMonth);
        //若有，则剔除掉该员工，重新组成列表，

        List<AttendEmployeeMonth> attendEmployeeMonthNew = new ArrayList<AttendEmployeeMonth>();

        for(AttendEmployeeMonth attendEmployeeMonth :attendEmployeeMonthList){
                for(AttendEmployeeMonth attendEmployeeMonthOld : attendEmployeeMonthListOld){
                    if (attendEmployeeMonth.getBtyArchicesId().equals(attendEmployeeMonthOld.getBtyArchicesId())){
                        attendEmployeeMonthNew.add(attendEmployeeMonth);
                }
            }
        }
        attendEmployeeMonthList.removeAll(attendEmployeeMonthNew);
        //若没有，直接进行之后的操作
        return attendEmployeeMonthList;
    }

    /**
     * （店长创建考勤页面） 根据督导的名字获取督导的信息；
     * @author wjk
     * @Date 2021-09-17
     */

    @Override
    public AttendAuditBtyArchives getDdInfoByName(String ddname) {
        LambdaQueryWrapper<AttendAuditBtyArchives> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(AttendAuditBtyArchives::getXm,ddname);
        List<AttendAuditBtyArchives> list = this.list(queryWrapper);

        AttendAuditBtyArchives attendAuditBtyArchives = new AttendAuditBtyArchives();
        //如果没有查询到督导的名字，则返回空
        if(list.size() ==  0 ){
            //return new AttendAuditBtyArchives();
        }
        //如果仅查询到一个名字，则该员工为督导信息
        if(list.size() ==  1 ){
            attendAuditBtyArchives = list.get(0);
        }
        //如果仅查询到多个名字，查询zw是督导的人，如果没有，则返回第一个人为督导
        if(list.size() > 0){
            for(int i = 0 ; i<list.size();i++){
                AttendAuditBtyArchives tmp = list.get(i);
                if(tmp.getZw().equals(RoleIdEnum.ROLE_DD.getMessage())){
                    attendAuditBtyArchives = list.get(i);
                    break;
                }
            }
            //若没有查询到督导信息，则返回一条数据为督导
            if(attendAuditBtyArchives == null){
                attendAuditBtyArchives = list.get(0);
            }
        }
        return attendAuditBtyArchives;
    }

    /**
     * （店长考勤修改页面+员工调店） 根据店长手机号，查询店长的营运经理，下的店的员工信息
     *
     *
     * @author wjk
     * @Date 2021-09-17
     */
    @Override
    public List<AttendAuditBtyArchives> getOperationsEmployeeListByDzPhone(String account,String xm) {

        AttendAuditBtyArea AttendAuditBtyArea = this.attendAuditBtyAreaService.getShopInfoByDzPhone(account);
        //营运经理的名字
        String OperationsName = AttendAuditBtyArea.getYyjl();
        //根据营运经理名字和员工姓名查询营运经理下的员工信息
        List<AttendAuditBtyArchives>  list = this.baseMapper.getOperationsEmployeeList(OperationsName,xm);

        return list;
    }
    /**
     * （店长考勤修改页面+员工调店） 根据店长手机号，查询店长的营运经理，下的店的员工信息，增加分页接口数据
     *
     *
     * @author wjk
     * @Date 2021-11-18
     */
    @Override
    public LayuiPageInfo getOperationsEmployeeListByDzPhoneLayuiPage(String account, String xm){

        AttendAuditBtyArea AttendAuditBtyArea = this.attendAuditBtyAreaService.getShopInfoByDzPhone(account);
        //营运经理的名字
        String OperationsName = AttendAuditBtyArea.getYyjl();
        //根据营运经理名字和员工姓名查询营运经理下的员工信息
        //List<AttendAuditBtyArchives>  list = this.baseMapper.getOperationsEmployeeList(OperationsName,xm);


        Page pageContext = getPageContext();
        IPage page = this.baseMapper.getOperationsEmployeeListPage(pageContext,OperationsName,xm);
        return LayuiPageFactory.createPageInfo(page);
    }

    /**
     * 查询一条数据，根据手机号
     * @author wjk
     * @Date 2021-09-22
     */
    @Override
    public AttendAuditBtyArchives getOneByPhone(String account) {
        LambdaQueryWrapper<AttendAuditBtyArchives> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(AttendAuditBtyArchives::getTel,account);
        List<AttendAuditBtyArchives> list = this.list(queryWrapper);
        AttendAuditBtyArchives attendAuditBtyArchives = new AttendAuditBtyArchives();
        if(list.size()>0){
            attendAuditBtyArchives =list.get(0);
        }
        return attendAuditBtyArchives;
    }
    /**
     * 查询一条数据，根据身份证
     * @author wjk
     * @Date 2021-11-08
     */
    @Override
    public AttendAuditBtyArchives getOneBySfz(String sfz){
        LambdaQueryWrapper<AttendAuditBtyArchives> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(AttendAuditBtyArchives::getSfz,sfz);
        List<AttendAuditBtyArchives> list = this.list(queryWrapper);
        AttendAuditBtyArchives attendAuditBtyArchives = new AttendAuditBtyArchives();
        if(list.size()>0){
            attendAuditBtyArchives =list.get(0);
        }
        return attendAuditBtyArchives;
    }
    /**
     * 根据考勤店长手机号，未获取员工信息的原因的提示！
     * @param account
     * @param list
     * @return
     */
    @Override
    public Map<String, String> getEmployeeListNullProblem(String account, List<AttendAuditBtyArchives> list) {
        Map<String, String> map = new HashMap<String, String>();
        map.put("message","");
        //获取店长的信息
        AttendAuditBtyArchives auditBtyArchives = getOneByPhone(account);
        if(ToolUtil.isEmpty(auditBtyArchives.getId())){
            map.put("message","当前登录账号，未在人事档案信息中，请联系督导，让督导找人事确认。");
            return map;
        }
        if(ToolUtil.isEmpty(auditBtyArchives.getDm())){
            map.put("message","您在人事档案中，未指定门店，请联系督导，让督导找人事指定门店。");
            return map;
        }
        AttendAuditBtyArea attendAuditBtyAreaDm = attendAuditBtyAreaService.getShopInfoByDm(auditBtyArchives.getDm());
        if(ToolUtil.isEmpty(attendAuditBtyAreaDm.getDm())){
            map.put("message","根据您所在的店，未查询到相关店信息，请确认此店("+auditBtyArchives.getDm()+")是否已经建店，或者被关闭。");
            return map;
        }
        if(ToolUtil.isEmpty(attendAuditBtyAreaDm.getKqDh())){
            map.put("message",""+auditBtyArchives.getDm()+"，未设置考勤店长，请联系督导或者大店长指定考勤店长。");
            return map;
        }
        if(!attendAuditBtyAreaDm.getKqDh().equals(account)){
            map.put("message","您当前登录的账号为:"+account+"，您所在店的考勤店长为:"+attendAuditBtyAreaDm.getKqDz()+",您所在店的考勤店长权限账号为:"+attendAuditBtyAreaDm.getKqDh()+"，请联系督导，让督导找人事更改手机号。");
            return map;
        }

        //获取店长所管辖的的店的信息
        AttendAuditBtyArea attendAuditBtyArea = this.attendAuditBtyAreaService.getShopInfoByDzPhone(account);

        //根据店名和手机获取员工列表信息
        List<AttendAuditBtyArchives> listArchives = getEmployeeListByDm(attendAuditBtyArea.getDm(),account);
        if(listArchives.size() == 0){
            map.put("message","根据店名和您的权限，查询到该店员工数量为0，如需要做考勤，请联系人事，为此店添加人员。");
            return map;
        }
        return map;
    }

    /**
     * //需要根据编号从人事中获取数据
     * @param attendEmployeeMonthOld
     * @return
     * @author wjk
     * @Date 2021-11-08
     */
    @Override
    public List<AttendEmployeeMonth> getAttendEmployeeMonthAuditBtyAreaServiceByBh(AttendEmployeeMonth attendEmployeeMonthOld){
        List<AttendEmployeeMonth> list = this.baseMapper.getAttendEmployeeMonthAuditBtyAreaServiceByBh(attendEmployeeMonthOld);
        return list;
    }
    /**
     * 获取人事中最新的数据,根据店名或者编号列表
     * @param attendAuditManagerSetResultList
     * @param dm
     * @return
     * @author wjk
     * @Date 2021-11-09
     */
    @Override
    public List<AttendAuditBtyArchives> getBtyArchivesListByBhListOrDm(List<AttendAuditManagerSetResult> attendAuditManagerSetResultList, String dm){
        List<AttendAuditBtyArchives> list = new ArrayList<AttendAuditBtyArchives>();
        if(attendAuditManagerSetResultList.size()>0){
            list = this.baseMapper.getBtyArchivesListByBhListOrDm(attendAuditManagerSetResultList,dm);
        }
        return list;
    }

    /**
     * 查询银行卡是否有重复数据，若有重复数据， 取出重复数据的人员信息(非此员工)，
     * @param attendEmployeeMonthParam
     * @return
     * @author wjk
     * @Date 2021-12-17
     */
    @Override
    public List<AttendAuditBtyArchives> getListByYhk(AttendEmployeeMonthParam attendEmployeeMonthParam) {
        List<AttendAuditBtyArchives> list = this.baseMapper.getListByYhk(attendEmployeeMonthParam);
        return list;
    }







    /**
     * 根据编号查询离职人员信息表
     * @param attendAuditManagerSetResult
     * @return
     * @author wjk
     * @Date 2021-12-20
     */

    @Override
    public List<AttendAuditBtyArchives> getArchivesListByBh(AttendAuditManagerSetResult attendAuditManagerSetResult) {
        List<AttendAuditBtyArchives> list = this.baseMapper.getArchivesListByBh(attendAuditManagerSetResult);
        return list;
    }
}
